import 'dart:convert';

import 'package:charts_flutter/flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_study/bean/charts_entity.dart';
import 'package:flutter_app_study/bean/up_data_entity.dart';
import 'package:flutter_app_study/generated/json/up_data_entity_helper.dart';
import 'package:flutter_app_study/utils/DioUtil.dart';

import '../../cost/ErpUrl.dart';

class ChartsFragment extends StatefulWidget {
  @override
  _ChartsFragmentState createState() => _ChartsFragmentState();
}

class _ChartsFragmentState extends State<ChartsFragment> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(bottom: 50),
      child: ListView(
        children: <Widget>[
          Container(
            child: getLine(),
            height: 300,
          ),
          Container(
            child: getBar(),
            height: 300,
          ),
          Container(
            child: getScatter(),
            height: 300,
          ),
          Container(
            child: getPie(),
            height: 300,
          ),
        ],
      ),
    );
  }

  Widget getLine() {
    List<LineChartsEntity> dataLine = [
      new LineChartsEntity(1, 20),
      new LineChartsEntity(2, 50),
      new LineChartsEntity(3, 20),
      new LineChartsEntity(4, 80),
      new LineChartsEntity(5, 120),
      new LineChartsEntity(6, 30),
    ];
    List<LineChartsEntity> dataLine2 = [
      new LineChartsEntity(1, 50),
      new LineChartsEntity(2, 30),
      new LineChartsEntity(3, 50),
      new LineChartsEntity(4, 60),
      new LineChartsEntity(5, 100),
      new LineChartsEntity(6, 20),
    ];
    var seriesBar = [
      Series(
          data: dataLine,
          domainFn: (LineChartsEntity entity, _) => entity.x,
          measureFn: (LineChartsEntity entity, _) => entity.y,
          id: "abc"),
      Series(
          data: dataLine2,
          domainFn: (LineChartsEntity entity, _) => entity.x,
          measureFn: (LineChartsEntity entity, _) => entity.y,
          id: "hhh")
    ];
    return LineChart(seriesBar);
  }

  Widget getBar() {
    List<BarChartsEntity> dataBar = [
      new BarChartsEntity("1", 20),
      new BarChartsEntity("2", 50),
      new BarChartsEntity("3", 20),
      new BarChartsEntity("4", 80),
      new BarChartsEntity("5", 120),
      new BarChartsEntity("6", 30),
    ];
    var seriesBar = [
      Series(
        data: dataBar,
        domainFn: (BarChartsEntity entity, _) => entity.x,
        measureFn: (BarChartsEntity entity, _) => entity.y,
        id: "abc",
      )
    ];
    return BarChart(seriesBar);
  }

  Widget getScatter() {
    List<LineChartsEntity> dataLine = [
      new LineChartsEntity(1, 20),
      new LineChartsEntity(2, 50),
      new LineChartsEntity(3, 20),
      new LineChartsEntity(4, 80),
      new LineChartsEntity(5, 120),
      new LineChartsEntity(6, 30),
    ];
    List<LineChartsEntity> dataLine2 = [
      new LineChartsEntity(1, 50),
      new LineChartsEntity(2, 30),
      new LineChartsEntity(3, 50),
      new LineChartsEntity(4, 60),
      new LineChartsEntity(5, 100),
      new LineChartsEntity(6, 20),
    ];
    var seriesBar = [
      Series(
          data: dataLine,
          domainFn: (LineChartsEntity entity, _) => entity.x,
          measureFn: (LineChartsEntity entity, _) => entity.y,
          id: "abc"),
      Series(
          data: dataLine2,
          domainFn: (LineChartsEntity entity, _) => entity.x,
          measureFn: (LineChartsEntity entity, _) => entity.y,
          id: "hhh")
    ];
    return ScatterPlotChart(seriesBar);
  }

  Widget getPie(){
    List<BarChartsEntity> dataBar = [
      new BarChartsEntity("1", 20),
      new BarChartsEntity("2", 50),
      new BarChartsEntity("3", 20),
      new BarChartsEntity("4", 80),
      new BarChartsEntity("5", 120),
      new BarChartsEntity("6", 30),
    ];
    var seriesBar = [
      Series(
        data: dataBar,
        domainFn: (BarChartsEntity entity, _) => entity.x,
        measureFn: (BarChartsEntity entity, _) => entity.y,
        id: "abc",
      )
    ];
    return PieChart(seriesBar);
  }
}
